
Imports System.Transactions


Public Class Form1

    Dim tiempo1 As Integer
    Dim tiempo2 As Integer
    Dim op1 As New Operacion1
    Dim op2 As New Operacion2


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Timer1.Interval = 1000
        Timer1.Start()

        Dim demora As TimeSpan

        Dim tiempoinicio As Date = Now


        While op1.CuentaRegistros1() > 0

            Using scope As TransactionScope = New TransactionScope()

                Try

                    Dim reg As Registro = op1.LeerRegistro()

                    TextBox1.Text = reg.Cuenta
                    TextBox2.Text = reg.Importe

                    op2.CopiarRegistro(reg)
                    op1.BorrarRegistro(reg)
          
                    TextBox3.Text = op1.CuentaRegistros1()
                    TextBox4.Text = op2.CuentaRegistros2()

                    ProgressBar1.Value = op1.CuentaRegistros1()
                    ProgressBar2.Value += 1

                    Me.Refresh()
                    Me.Update()

                    Transacion += 1

                    scope.Complete()

                Catch ex As Exception
                    MsgBox(ex.Message)
                    scope.Dispose()
                End Try

            End Using

            Application.DoEvents()

            demora = Now - tiempoinicio

            TextBox7.Text = demora.Minutes.ToString & "   " & demora.Seconds.ToString

        End While

    End Sub



    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ProgressBar1.Maximum = op1.CuentaRegistros1()
        ProgressBar2.Maximum = op1.CuentaRegistros1()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim TranssacionesPorSegundo As Integer = Transacion - tiempo2
        tiempo2 = Transacion

        TextBox5.Text = TranssacionesPorSegundo

        Try
            Dim Segundos As Integer = Int(op1.CuentaRegistros1() / TranssacionesPorSegundo)
            Dim MinutosTotales As Integer = Int(Segundos / 60)
            Dim SegundosRestantes As Integer = Segundos - MinutosTotales * 60
            TextBox6.Text = MinutosTotales & "  " & SegundosRestantes

        Catch ex As Exception

        End Try

    End Sub

    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim a As TimeSpan
        a = Now.TimeOfDay
        MsgBox(a.ToString)


    End Sub
End Class
